package com.xin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author WYX
 * @create 2020-04-05-15:44
 */
@Controller
@RequestMapping("/user")
public class LoginController {

    @RequestMapping("/main")
    public String main(){
        return "main";
    }

    @RequestMapping("/goLogin")
    public String login(){
        return "login";
    }
    @RequestMapping("/login")
    public String login(HttpSession httpSession, String username , String password , Model model){
        //把用户的信息存在session中，
        httpSession.setAttribute("userLoginInfo",username);
        System.out.println(username);
        model.addAttribute("username",username);
        return "main";
    }

    @RequestMapping("/goOut")
    public String goOut(HttpSession httpSession){
       httpSession.removeAttribute("userLoginInfo");
        return "login";
    }
}
